import Vue from "vue";
import request from "@/itsoftUI/utils/request";
import qs from "qs";
const baseUrl = Vue.prototype.$itsoftUI.config.serviceUrl + "/database";

//数控库连接
const apiDatabase = {
  // 获取数据库连接列表
  getList: function() {
    const data = {
      repositoryId: Vue.prototype.$repositoryId
    };
    return request({
      url: baseUrl + "/list",
      method: "post",
      data: qs.stringify(data)
    });
  },
  // 获取数据库类型
  types: function() {
    return request({
      url: baseUrl + "/types",
      method: "post"
    });
  },
  // 获取数据库连接类型
  conTypes: function(databaseType) {
    const data = {
      databaseType
    };
    return request({
      url: baseUrl + "/conTypes",
      method: "post",
      data: qs.stringify(data)
    });
  },
  // 获取数据库连接详情
  open: function(databaseId) {
    const data = {
      repositoryId: Vue.prototype.$repositoryId,
      databaseId
    };
    return request({
      url: baseUrl + "/open",
      method: "post",
      data: qs.stringify(data)
    });
  },
  // 保存
  save: function(jsonDatabaseMeta) {
    const data = {
      repositoryId: Vue.prototype.$repositoryId,
      jsonDatabaseMeta
    };
    return request({
      url: baseUrl + "/save",
      method: "post",
      data: qs.stringify(data)
    });
  },
  // 保存
  delete: function(databaseId) {
    const data = {
      repositoryId: Vue.prototype.$repositoryId,
      databaseId
    };
    return request({
      url: baseUrl + "/delete",
      method: "post",
      data: qs.stringify(data)
    });
  },
  // 测试
  test: function(databaseInfo) {
    const data = {
      databaseInfo
    };
    return request({
      url: baseUrl + "/test",
      method: "post",
      data: qs.stringify(data)
    });
  },
  // 特征列表
  features: function(databaseInfo) {
    const data = {
      databaseInfo
    };
    return request({
      url: baseUrl + "/features",
      method: "post",
      data: qs.stringify(data)
    });
  },
  // 特征列表
  explorer: function(databaseInfo, type) {
    const data = {
      databaseInfo,
      type
    };
    return request({
      url: baseUrl + "/explorer",
      method: "post",
      data: qs.stringify(data)
    });
  }
};
export { apiDatabase };
